﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClientAppraise.ViewModels.Validator
{
    public sealed class ZxRequiredAttribute : ValidationAttribute
    {
        readonly int min = 1;
        public ZxRequiredAttribute(int min = 1)
        {
            this.min = min;
        }

        protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
        {
            if (value == default || string.IsNullOrEmpty(value.ToString()))
            {
                return new("此项不可以为空");
            }

            if ((value.ToString()??"").Length < min)
            {

                return new($"此项长度必需大于{min}");
            }


            return ValidationResult.Success;
        }
    }
}
